package fit.deni.beans;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;

import com.sun.istack.internal.NotNull;

@Entity
@Table(name = "Zaposleni")
public class Zaposleni {

	@Id
	@GeneratedValue
	private int id;
	@Validate("required")
	private String ime;
	@Validate("required")
	private String jmbg;
	@OneToMany
	private List<Telefon> telefoni;
	private String email;
	@ManyToOne
	@Validate("required")
	private Klub zaposlenUKlubu;
	private String username;
	private int passwordHash;
	@NotNull
	private int role;
	private Date lastLoggedIn;
	@Transient
	public final static int ADMINISTRATOR = 1, USER = 2;
	@NonVisual
	private boolean deleted;
	
	public boolean isDeleted() {
		return deleted;
	}
	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public Klub getZaposlenUKlubu() {
		return zaposlenUKlubu;
	}

	public void setZaposlenUKlubu(Klub zaposlenUKlubu) {
		this.zaposlenUKlubu = zaposlenUKlubu;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getIme() {
		return ime;
	}

	public void setIme(String ime) {
		this.ime = ime;
	}

	public String getJmbg() {
		return jmbg;
	}

	public void setJmbg(String jmbg) {
		this.jmbg = jmbg;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public List<Telefon> getTelefoni() {
		return telefoni;
	}

	public void setTelefoni(List<Telefon> telefoni) {
		this.telefoni = telefoni;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public int getPasswordHash() {
		return passwordHash;
	}

	public void setPasswordHash(int passwordHash) {
		this.passwordHash = passwordHash;
	}

	public int getRole() {
		return role;
	}

	public void setRole(int role) {
		this.role = role;
	}

	public Date getLastLoggedIn() {
		return lastLoggedIn;
	}

	public void setLastLoggedIn(Date lastLoggedIn) {
		this.lastLoggedIn = lastLoggedIn;
	}
	
	@Transient
	public boolean isAdmin() {
		return (getRole()==Zaposleni.ADMINISTRATOR); 
	}

}
